﻿<UserControl x:Class="AutomationMLMapper.Controls.CAEXCollectionView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" 
             xmlns:local="clr-namespace:AutomationMLMapper.Controls"
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/AutomationMLMapper;component/StyleResources/ListStyle.xaml"/>
                <ResourceDictionary Source="/AutomationMLMapper;component/StyleResources/Templates.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <Style x:Key="ListBoxStyle" TargetType="{x:Type ListBox}">
                <Setter  Property="ItemTemplateSelector" Value="{StaticResource EditableAutomationMLTemplateSelector}"></Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=AllowEditElement}" Value="True">
                        <Setter  Property="ItemTemplateSelector" Value="{StaticResource EditableAutomationMLTemplateSelector}"></Setter>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=AllowEditElement}" Value="False">
                        <Setter  Property="ItemTemplateSelector" Value="{StaticResource ReadOnlyAutomationMLTemplateSelector}"></Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="ControlGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <Expander Header="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.DisplayName}" 
                  Style="{StaticResource StretchedExpanderStyle}"
                  IsExpanded="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.IsExpanded, Mode=TwoWay}"
				  HeaderTemplate="{StaticResource ExpanderHeader}" Grid.ColumnSpan="2"
				  Grid.Column="0" MinWidth="300">
            <ListBox Grid.IsSharedSizeScope="True" IsSynchronizedWithCurrentItem="True"                      
                    VirtualizingStackPanel.IsVirtualizing="True"
                    VirtualizingStackPanel.VirtualizationMode="Recycling"
                    ScrollViewer.IsDeferredScrollingEnabled="True"
                    ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.View}" 
                    Style="{StaticResource ListBoxStyle}">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.GroupStyle>
                    <GroupStyle ContainerStyle="{StaticResource ListGroupStyle}">
                    </GroupStyle>
                </ListBox.GroupStyle>
            </ListBox>
        </Expander>

        <local:AddDeleteItemControl HorizontalAlignment="Right" Grid.Column="1" x:Name="CommandButtons" 
                                    ButtonAddToolTip="{Binding ElementName=ControlGrid, Path=DataContext.ElementDisplayName, StringFormat=add {0}}"
                                    ButtonAddCommand="{Binding ElementName=ControlGrid, Path=DataContext.AddCommand}"
                                    ButtonDeleteCommand="{Binding ElementName=ControlGrid, Path=DataContext.DeleteCommand}"
                                    ButtonDeleteToolTip="{Binding ElementName=ControlGrid, Path=DataContext.ElementDisplayName, StringFormat=delete the selected {0}}">

        </local:AddDeleteItemControl>
    </Grid>
</UserControl>
